﻿<!-- ReSharper disable Xaml.RedundantNamespaceAlias -->
<Window  x:Name="AppMainWindow"
        x:Class="WpfDemoApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mark="MvvmBindingPack"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:vm="clr-namespace:WpfDemoApplication.ViewModel"
        Title="MVVM-WPF-WinRt Markup Binding Extensions" 
        Height="350" Width="525"
        DataContext="{StaticResource MainWindowViewModel}" 
        Loaded="{mark:BindEventHandler  MethodName=Loaded}"
        Unloaded="{mark:BindEventHandler MethodName=Unloaded}" 
         >
    <!-- ReSharper restore Xaml.RedundantNamespaceAlias -->

    <!--<Window.Resources>
        <vm:MainWindowVm x:Key="MainWindowViewModel"/>
    </Window.Resources>-->


    <!-- XAML TRICK TO ADD HANDLERS ( but ?!? ) -->
    <!--
    <Window.Loaded>
        <mark:BindEventHandlerResource ResourceKey="MainWindowViewModel" MethodName="Loaded"/>
    </Window.Loaded>
    
    <Window.Unloaded>
        <mark:BindEventHandlerResource ResourceKey="MainWindowViewModel" MethodName="Unloaded"/>
    </Window.Unloaded>

    <Window.Closed>
        <mark:BindEventHandlerResource ResourceKey="MainWindowViewModel" MethodName="Closed"/>
    </Window.Closed>
    -->

    <!-- Put model loaded unloaded notifications in Grid -->
    <!-- DataContext below will be skipped as it doesn't contain matching methods -->
    <!---->
    <Grid DataContext="{StaticResource MainWindowViewModelAdditional}" >
        <Grid>
            <Button Content="Button Click Method" HorizontalAlignment="Left" Margin="27,19,0,0" VerticalAlignment="Top" Width="120" Click="{mark:BindEventHandler MethodName=AddButtonClickMethod}">
            </Button>
            <Label DataContext="{mark:LocateDataContext vm:MainWindowVMAdditional,PropertyName=MarkerAdditional}" 
                   Content="{Binding AddButtonClickMethodMsg}"
               HorizontalAlignment="Left" Margin="158,19,0,0" VerticalAlignment="Top" Width="323" Background="#FFCDC9C9"/>

            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Button Click Method" HorizontalAlignment="Left" Margin="27,19,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandlerResource MainWindowViewModel,MethodName=ButtonClickMethod}"/>
        <Button Content="Button Click Method" HorizontalAlignment="Left" Margin="27,19,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandlerResource ResourceKey=MainWindowViewModel,MethodName=ButtonClickMethod}"/>
        
        <Button Content="Button Click Method" HorizontalAlignment="Left" Margin="27,19,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandler Source={StaticResource MainWindowViewModel},MethodName=ButtonClickMethod}"/>
        <Button Content="Button Click Method" HorizontalAlignment="Left" Margin="27,19,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandler {StaticResource MainWindowViewModel},MethodName=ButtonClickMethod}"/>
        -->


            <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandler PropertyName=AddButtonClickPropDelegate}"/>
            <Label DataContext="{mark:LocateDataContext PropertyName=MarkerAdditional}" 
                   Content="{Binding AddButtonClickPropMsg}"
               HorizontalAlignment="Left" Margin="158,43,0,0" VerticalAlignment="Top" Width="323" Background="#FFCDC9C9"/>



            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandlerResource ResourceKey=MainWindowViewModel,PropertyName=ButtonClickPropDelegate}"/>
        <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandlerResource ResourceKey=MainWindowViewModel,PropertyName=CommandProxy}"/>
        
        <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandler Source={StaticResource MainWindowViewModel},PropertyName=ButtonClickPropDelegate}"/>
        <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandler {StaticResource MainWindowViewModel},PropertyName=ButtonClickPropDelegate}"/>
        <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandler PropertyName=CommandProxy}"/>
        <Button Content="Button Click PropDel" HorizontalAlignment="Left" Margin="27,43,0,0" VerticalAlignment="Top" Width="120"
                Click="{mark:BindEventHandlerResource MainWindowViewModel,PropertyName=ButtonClickPropDelegate}"/>
        -->

            <Button Content="Button Cmd-Ex " HorizontalAlignment="Left" Margin="27,97,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  ExecuteMethodName=ExecuteMethod,DeepScanAllTrees=True}"/>

            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Button Cmd-Ex " HorizontalAlignment="Left" Margin="27,97,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource MainWindowViewModel,ExecuteMethodName=ExecuteMethod}"/>
       
        <Button Content="Button Cmd-Ex " HorizontalAlignment="Left" Margin="27,97,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  Source={StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod}"/>
        <Button Content="Button Cmd-Ex " HorizontalAlignment="Left" Margin="27,97,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  {StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod}"/>
     
        <Button Content="Button Cmd-Ex " HorizontalAlignment="Left" Margin="27,97,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecuteMethodName=ExecuteMethod}"/>
        -->

            <Button Content="Property Cmd-ExCe" HorizontalAlignment="Left" Margin="27,121,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand ExecutePropertyName=ButtonExecuteProperty,CanExecutePropertyName=CanExecuteProperty,
                DeepScanAllTrees=True}"/>

            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Property Cmd-ExCe" HorizontalAlignment="Left" Margin="27,121,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecutePropertyName=ButtonExecuteProperty,
                CanExecutePropertyName=CanExecuteProperty}"/>

        <Button Content="Property Cmd-ExCe" HorizontalAlignment="Left" Margin="27,121,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand Source={StaticResource MainWindowViewModel},ExecutePropertyName=ButtonExecuteProperty,
                CanExecutePropertyName=CanExecuteProperty}"/>
        <Button Content="Property Cmd-ExCe" HorizontalAlignment="Left" Margin="27,121,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand {StaticResource MainWindowViewModel},ExecutePropertyName=ButtonExecuteProperty,
                CanExecutePropertyName=CanExecuteProperty}"/>
        <Button Content="Property Cmd-ExCe" HorizontalAlignment="Left" Margin="27,121,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecutePropertyName=ButtonExecuteProperty,
                CanExecutePropertyName=CanExecuteProperty}"/>
        -->

            <Button Content="Button Cmd-ExCeEv" HorizontalAlignment="Left" Margin="27,162,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,EventToInvokeCanExecuteChanged=ActionNotifyCanExecuteChanged,DeepScanAllTrees=True}"/>
            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Button Cmd-ExCeEv" HorizontalAlignment="Left" Margin="27,162,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,EventToInvokeCanExecuteChanged=EventHandlerNotifyCanExecuteChanged}"/>

        <Button Content="Button Cmd-ExCeEv" HorizontalAlignment="Left" Margin="27,162,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  Source={StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,EventToInvokeCanExecuteChanged=EventHandlerNotifyCanExecuteChanged}"/>
        <Button Content="Button Cmd-ExCeEv" HorizontalAlignment="Left" Margin="27,162,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  {StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,EventToInvokeCanExecuteChanged=EventHandlerNotifyCanExecuteChanged}"/>
        <Button Content="Button Cmd-ExCeEv" HorizontalAlignment="Left" Margin="27,162,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,EventToInvokeCanExecuteChanged=EventHandlerNotifyCanExecuteChanged}"/>
        <Button Content="Button Cmd-ExCeEv" HorizontalAlignment="Left" Margin="27,162,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,EventToInvokeCanExecuteChanged=ActionNotifyCanExecuteChanged}"/>
        -->

            <Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,186,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,PropertyActionCanExecuteChanged=PropertyDelegateNotifyCanExecuteChanged,
                DeepScanAllTrees=True}"/>

            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,186,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,PropertyActionCanExecuteChanged=PropertyDelegateNotifyCanExecuteChanged}"/>
        <Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,186,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource MainWindowViewModel,ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,PropertyActionCanExecuteChanged=PropertyDelegateNotifyCanExecuteChanged}"/>

        <Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,186,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand Source={StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,PropertyActionCanExecuteChanged=PropertyDelegateNotifyCanExecuteChanged}"/>
        <Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,186,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand {StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,PropertyActionCanExecuteChanged=PropertyDelegateNotifyCanExecuteChanged}"/>
        <Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,186,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand ExecuteMethodName=ExecuteMethod,
                CanExecuteMethodName=CanExecuteMethod,PropertyActionCanExecuteChanged=PropertyDelegateNotifyCanExecuteChanged}"/>
        -->
            <Button Content="Button Cmd-ExProp" HorizontalAlignment="Left" Margin="27,210,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  ExecuteMethodName=ExecuteMethod,
                CanExecuteBooleanPropertyName=CanExecuteFlag,DeepScanAllTrees=True}"/>

            <!--  Can also be used like these -->
            <!-- 
        <Button Content="Button Cmd-ExProp" HorizontalAlignment="Left" Margin="27,210,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource ResourceKey=MainWindowViewModel,ExecuteMethodName=ExecuteMethod,
                CanExecuteBooleanPropertyName=CanExecuteFlag}"/>

        <Button Content="Button Cmd-ExProp" HorizontalAlignment="Left" Margin="27,210,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  Source={StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod,
                CanExecuteBooleanPropertyName=CanExecuteFlag}"/>
        <Button Content="Button Cmd-ExProp" HorizontalAlignment="Left" Margin="27,210,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommand  {StaticResource MainWindowViewModel},ExecuteMethodName=ExecuteMethod,
                CanExecuteBooleanPropertyName=CanExecuteFlag}"/>
        <Button Content="Button Cmd-ExProp" HorizontalAlignment="Left" Margin="27,210,0,0" VerticalAlignment="Top" Width="120"
                Command="{mark:BindCommandResource WeakBinding=True,ResourceKey=MainWindowViewModel,ExecuteMethodName=ExecuteMethod,
                CanExecuteBooleanPropertyName=CanExecuteFlag}"/>
        -->

            <Button Content="Button Cmd-Binding" HorizontalAlignment="Left" Margin="27,277,0,0" VerticalAlignment="Top" Width="120"
               Command="{Binding CommandProxy,Source={StaticResource MainWindowViewModel}}"/>

            <Label Content="{Binding ButtonCommandMsgVariantOne, Source={StaticResource MainWindowViewModel}}"
               HorizontalAlignment="Left" Margin="158,97,0,0" VerticalAlignment="Top" Width="323" Background="#FFCDC9C9"/>

            <CheckBox Content="CanExecute Flag" HorizontalAlignment="Left" Margin="158,162,0,0" VerticalAlignment="Top" Width="134" 
                  IsChecked="{Binding CanExecuteFlag,Mode=TwoWay, Source={StaticResource MainWindowViewModel}}"/>
        </Grid>
    </Grid>
</Window>
